package com.tutorial.sqlSession;

import com.tutorial.config.XMLConfigBuilder;
import com.tutorial.pojo.Configuration;

import java.io.InputStream;

/**
 * SqlSession会话工厂构建类
 *
 * @author: GXW
 * @since: 2025-10-29 08:57:38
 **/
public class SqlSessionFactoryBuilder {
    public SqlSessionFactory build(InputStream inputStream) throws Exception {
        // 第一步：用dom4j解析配置文件，将解析出来的内容封装到Configuration中
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(inputStream);

        // 第二步：创建sqlSessionFactory对象，生产sqlSession会话对象（工厂模式）
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return defaultSqlSessionFactory;
    }
}
